﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Permission.Interfaces;
using Micrhard.FMCG.Server.DataAccess;
using Micrhard.FMCG.Server.Models;

namespace Micrhard.FMCG.Server.Impl
{
    public class UserGetSubKAValidator : ICustomeDataPermissionValidator
    {
        public bool HasPermission(List<Guid> identity)
        {
            if (identity.First() == Guid.Empty)
                return true;
            MicrhardFMCGServerEntities db = new MicrhardFMCGServerEntities();
            var emp = db.Employees.SingleOrDefault(e => e.UserName == this.scope.CurrentUserName);
            if (emp.Range == (int)Range.Manager)
                return true;
            var cnt = emp.ManagementScopes.Count(s => identity.Contains(s.SubID.Value));
            return cnt > 0 ? true : false;
        }

        public Microhard.Core.DBUtility.ScopeResult scope
        {
            set;
            get;
        }
    }
}
